import java.util.Scanner;
public class MenuDrivenProgram{
   public static void main(String[] args){
      Scanner kbscanner = new Scanner(System.in);
      int num1= 0, num2= 0, result, choice;
      
      do{
         choice = menu();
         
         switch(choice){
            case 1:
            case 2:
            case 3: System.out.println("Enter two integers: ");
                    num1 = kbscanner.nextInt();
                    num2 = kbscanner.nextInt();
          }
          
          switch(choice){
            case 1: System.out.printf("%d + %d = %d%n", num1, num2, add(num1,num2));
                    break;
            case 2: System.out.printf("%d - %d = %d%n", num1, num2, subtract(num1,num2));
                    break;
            case 3: System.out.printf("%d * %d = %d%n", num1, num2, multiply(num1,num2));
                    break;
            case 4: break;
            default: System.out.printf("Error: Invalid choice%n");
          }
           
           
           if(choice >=1 && choice <= 3){
           	 kbscanner.nextLine();  // remove the new-line character left in the input buffer after reading
           	                        // the two integer values
             System.out.println("Press Enter key to continue . . .");
             kbscanner.nextLine();  // read the key press  
           }
           else if(choice != 4){
           	 System.out.println("Press Enter key to continue . . .");
             kbscanner.nextLine();  // read the key press 
           }       
                    
      }while(choice != 4);
   }
   
   public static int menu(){
   	     Scanner scanner = new Scanner(System.in);
   	     System.out.println("1. Addition");
         System.out.println("2. Subtraction");
         System.out.println("3. Multiplication");
         System.out.println("4. Exit");
         
         System.out.println("Please select your choice: ");
         int selection = scanner.nextInt();
         return selection;
   }
   
   public static int add(int x, int y){
   	   return x + y;
   }
   
    public static int subtract(int x, int y){
   	   return x - y;
   }
   
    public static int multiply(int x, int y){
   	   return x * y;
   }
}